<template>
	<view>
		<view class="text-gray padding justify-center flex align-center" v-if="!pageLoad">
			<u-loading mode="circle" color="#2979ff" size="40"></u-loading>
			<view class="margin-left-sm">加载中...</view>
		</view>
		<view v-if="pageLoad">
			<view class="cu-list menu-avatar">
				<view class="cu-item">
					<!-- 头像 -->
					<view @click="tohis(author._id)" class="cu-avatar round lg">
						<image style="width: 100%;height: 100%;" :src="author.avatar" mode=""></image>
					</view>
					<view class="content flex-sub">
						<view class="jiacu">{{author.ssuserid}}</view>
						<view class="jiacu">{{author.nickname}}</view>
						<!-- <view class="text-gray flex justify-between">
							<view class="text-sm jiacu">粉丝：{{fans}} 关注：{{blogger}}</view>
							<view class="margin-right-sm">
								<button v-if="focus == true" @click="cancelFocus"
									class="cu-btn shadow bg-grey sm jiacu">已关注</button>
								<button v-else-if="focus == false" @click="focusOn"
									class="cu-btn shadow bg-red sm jiacu">关注</button>
							</view>
						</view> -->
					</view>
				</view>
			</view>
			<!-- 内容 -->
			<view class="cu-card no-card margin-top">
				<view class="padding neibianju">
					<view class="text-content margin-top-sm">
						标题：{{data.title}}
					</view>
					<view class="text-content margin-top-sm">
						时间：{{data.time}}
					</view>
					<view class="text-content margin-top-sm">
						地点：{{data.address}}
					</view>
					<view class="text-content margin-top-sm">
						价格：{{data.money}}
					</view>
					<view class="text-content margin-top-sm">
						需求类型：{{typeName(data.type)}}
					</view>
					<view class="" v-if="data.showPhone">
						<view class="text-content margin-top-sm">
							联系人：{{data.userName}}
						</view>
						<view class="text-content margin-top-sm">
							联系方式：{{data.userPhone}}
						</view>
					</view>
					<view class="text-gray flex justify-end"></view>
					<!-- 视频 -->
					<view class="image videoSrc" v-if="data.srcVideo">
						<video :src="data.srcVideo"></video>
					</view>
					<!-- 图片 -->
					<view class="image" v-if="data.imgList.length == 1">
						<image mode="aspectFit" :src="data.imgList[0].imgurl" data-src="0" @tap="openImg">
						</image>
					</view>
					<view class="image" v-if="data.imgList.length > 1">
						<view class="imagesList">
							<image mode="aspectFit" v-for="(itemImg,indexImg) in data.imgList" :key="indexImg"
								:data-src="index" @tap="openImg" :src="itemImg.imgurl"></image>
						</view>
					</view>
					<view class="text-gray flex justify-end">{{data.createTime}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import list from '../../common/new.js'
	export default {
		data() {
			return {
				id: '',
				detail: {},
				data: {},
				author: {},
				pageLoad: false,
				list: list,
			}
		},
		onLoad(e) {
			this.id = e.id
			this.init()
		},
		methods: {
			typeName(item) {
				if (item) {
					return this.list[item].title
				}
			},
			init() {
				var that = this
				uniCloud.callFunction({
					name: 'announcement',
					data: {
						cloudAction: "show",
						params: {
							id: that.id
						}
					}
				}).then((res) => {
					if (res.result.error == 0) {
						that.detail = res.result.data
						that.data = res.result.data.data
						that.author = res.result.data.user
						that.pageLoad = true;
					} else {
						uni.showToast({
							title: res.result.message,
							icon: "none",
						})
						if (res.result.code == 30203) {
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages/login/index'
								})
							}, 800)
						}
					}
				}).catch((err) => {
					console.error(err)
				})
			}
		}
	}
</script>

<style>

</style>
